package com.yunche.yunchebusiness.common

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import com.afollestad.materialdialogs.MaterialDialog

/**
 * Create by Crcker on 2018/10/10 09:52
 * Email: Crcker@163.com
 */


object CommonDialog {
    @SuppressLint("StaticFieldLeak")
    private var progressDialog: MaterialDialog? = null

    fun showLoading(context: Context, msg: String) {
        if (progressDialog == null) {
            progressDialog = MaterialDialog.Builder(context)
                    .content(msg)
                    .progress(true, 0)
                    .progressIndeterminateStyle(true)
                    .cancelable(false)
                    .show()
        } else {
            if (!progressDialog!!.isShowing) {
                try {
                    progressDialog!!.show()
                } catch (e: Exception) {
                    e.printStackTrace()
                }

            }
        }
    }



    fun showErrorDialog(context: Context, title: String, msg: String) {
        MaterialDialog.Builder(context)
                .title(title)
                .content(msg)
                .positiveText("确定")
                .cancelable(false)
                //.icon(context.getResources().getDrawable(R.drawable.ic_item_dialog_error))
                .show()


    }


    fun showSuccessDialog(context: Context, title: String, msg: String) {
        MaterialDialog.Builder(context)
                .title(msg)
                .content(title)
                .contentColor(Color.RED)
                .cancelable(false)
                .positiveText("确定")
                //.icon(context.getResources().getDrawable(R.drawable.ic_item_dialog_ok))
                .show()

    }


    //关闭 间隔1s
    fun cancle() {
        try {
            if (progressDialog != null) {
                progressDialog!!.dismiss()
                progressDialog = null
            }

        } catch (e: Exception) {
        }

    }
}